package tianyin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tianyin.dao.IShopcartDao;
import tianyin.model.Shopcart;
import tianyin.service.IShopcartService;

@Controller
@RequestMapping("/mall/html/shopcart")
public class ShopcartController {

	@Resource
	private IShopcartDao shopcartDao;
	@Resource
	private IShopcartService shopcartService;
	
	
	//查询用户购物车
	@RequestMapping("/findCartByUser.do")
	@ResponseBody
	public Map findCartByUser(int uid){
		List<Shopcart> list	= shopcartDao.findCartByUser(uid);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("status", 0);
		map.put("infoList", list);
		return map;
	}
	
	//添加到购物车
	@RequestMapping("/addCart.do")
	@ResponseBody
	public int addCart(Shopcart cart) {
		return shopcartService.addCart(cart);
	}
	
	//删除购物车记录
	@RequestMapping("/delCart.do")
	@ResponseBody
	public int delCart(int id) {
		return shopcartDao.delCart(id);
	}
	
	//修改购物车商品数量
	@RequestMapping("/addCartNum.do")
	@ResponseBody
	public int addCartNum(int id,int num) {
		return shopcartDao.addCartNum(id, num);
	}
	
	//查询用户购物车商品种数
	@RequestMapping("/getCount.do")
	@ResponseBody
	public int getCount(int uid) {
		return shopcartDao.getCount(uid);
	}
	
}
